﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESOL.Common;
using ESOL.WinUI.UICommon;
using ESOL.Common.Entity;
using ESOL.Business.Mst;
using ESOL.Business.Prod;
using ESOL.Business.Proj;
using ESOL.WinUI.Bpt;

namespace ESOL.WinUI.Manufacture
{
    public partial class frmMaintainPickingPlan : BaseForm.frmBaseDialogyMaintainForm
    {
        #region vars
        public ActionType ThisActionType { set; get; }
        private ProdPickingMaterialEntity mSelectedPickingMaterial;
        private List<ProdPlanOrderItemEntity> listSelectedPlanOrderItem;
        #endregion

        #region ctors
        public frmMaintainPickingPlan()
        {
            InitializeComponent();
        }
        public frmMaintainPickingPlan(List<ProdPlanOrderItemEntity> list)
        {
            InitializeComponent();
            listSelectedPlanOrderItem = list;
        }
        public frmMaintainPickingPlan(ProdPickingMaterialEntity entity)
        {
            InitializeComponent();
            mSelectedPickingMaterial = entity;
        }
        #endregion

        #region functions
        private void Init()
        {
            if (ThisActionType == ActionType.New)
            {
                btnSave.Enabled = true;
            }
            else if (ThisActionType == ActionType.Modify)
            {
                btnSave.Enabled = true;
            }
            else if (ThisActionType == ActionType.View)
            {
                btnSave.Enabled = false;
            }
        }
        private void BindComboBox()
        {
            UICommon.UICommonFunctions.BindComboboxByCommonItem(cmbPickingType, "PIKT", true);
            UICommon.UICommonFunctions.BindComboboxByCommonItem(cmbStatus, "PIK", false);

            DataTable dt = MstCommonItemBs.GetMstCommonItemDtByType("PICKT");
            repositoryItemGridLookUpEdit1.DataSource = dt;
            repositoryItemGridLookUpEdit1.DisplayMember = "ITEM_NAME";
            repositoryItemGridLookUpEdit1.ValueMember = "ITEM_CODE";

        }
        private void SetField()
        {
            if (ThisActionType == ActionType.New)
            {
                MstDepartmentEntity m = MstDepartmentBs.GetMstDepartmentByID(Common.CommonParameter.CurrentUser.PersonEntity.DepartmentId);
                txtPickingDpt.Tag = m;
                txtPickingDpt.Text = m.DepartmentName;
                txtPickingPerson.Tag = Common.CommonParameter.CurrentUser.PersonEntity;
                txtPickingPerson.Text = Common.CommonParameter.CurrentUser.ChineseName;
                UICommonFunctions.SetTextBoxDate(txtCreatedDate, DateTime.Today, "yyyy-MM-dd");
                UICommonFunctions.SetTextBoxPersonName(txtCreatedBy, CommonParameter.CurrentUser.PersonId);
                cmbStatus.SetSelectedValue("PIK01");
            }
            else if (ThisActionType == ActionType.Modify || ThisActionType == ActionType.View)
            {
                if (mSelectedPickingMaterial == null)
                    return;
                MstDepartmentEntity mMstDpt = MstDepartmentBs.GetMstDepartmentByID(mSelectedPickingMaterial.PickingDepartment);
                if (mMstDpt == null)
                    return;
                MstPersonEntity mMstPerson = MstPersonBs.GetMstPersonByID(mSelectedPickingMaterial.PickingPerson);
                if (mMstPerson == null)
                    return;
                cmbPickingType.SetSelectedValue(mSelectedPickingMaterial.PickingType);
                txtPickingDpt.Text = mMstDpt.DepartmentName;
                txtPickingDpt.Tag = mMstDpt;
                txtPickingPerson.Text = mMstPerson.NameCn;
                txtPickingPerson.Tag = mMstPerson;
                dtpPlanDeliveryDate.EditValue = mSelectedPickingMaterial.PlanDeliveryDate;
                txtRemark.Text = mSelectedPickingMaterial.Remark;
                UICommonFunctions.SetTextBoxDate(txtCreatedDate, mSelectedPickingMaterial.CreatedDate, "yyyy-MM-dd");
                UICommonFunctions.SetTextBoxPersonName(txtCreatedBy, mSelectedPickingMaterial.CreatedBy);
                UICommonFunctions.SetTextBoxDate(txtLastModifiedDate, DateTime.Today, "yyyy-MM-dd");
                UICommonFunctions.SetTextBoxPersonName(txtLastModifiedBy, CommonParameter.CurrentUser.PersonId);
                UICommonFunctions.SetTextBoxDate(txtApprovedDate, mSelectedPickingMaterial.ApprovedDate, "yyyy-MM-dd");
                UICommonFunctions.SetTextBoxPersonName(txtApprovedBy, mSelectedPickingMaterial.ApprovedBy);
            }
        }
        private void BindGrid()
        {
            #region 新增
            if (ThisActionType == ActionType.New)
            {
                DataTable dt = ProdPickingMaterialItemBs.GetDtPickingMaterialItemByCondition(" AND 1=2", "");
                gvMain.DataSource = dt;
                if (listSelectedPlanOrderItem == null)
                {
                    return;
                }
                foreach (ProdPlanOrderItemEntity m in listSelectedPlanOrderItem)
                {
                    DataTable dtExistedPickingStation = ProdProductTechnicBs.GetExistedPickingStationByPlanOrderItemID(m.PlanOrderItemId);
                    if (dtExistedPickingStation.Rows.Count == 0)
                    {
                        continue;
                    }
                    DataTable dtBomProductMaterial = ProjMBOMMaterialBs.GetDtAllByProductID(m.ProductId); //如果存在BOM原材料
                    if (dtBomProductMaterial.Rows.Count > 0)
                    {
                        foreach (DataRow drBomProductMaterial in dtBomProductMaterial.Rows)
                        {
                            DataRow dr = dt.NewRow();
                            dr["PICKING_MATERIAL_ITEM_ID"] = Guid.NewGuid().ToString();
                            dr["PLAN_ORDER_ITEM_ID"] = m.PlanOrderItemId;
                            dr["MATERIAL_ID"] = drBomProductMaterial["MATERIAL_ID"];
                            dr["PRODUCT_TECHNIC_ID"] = dtExistedPickingStation.Rows[0]["PRODUCT_TECHNIC_ID"];
                            dr["QTY"] = m.Qty;
                            dr["NET_SIZE"] = drBomProductMaterial["NET_SIZE"];
                            dr["GROSS_SIZE"] = drBomProductMaterial["GROSS_SIZE"];
                            dr["UNIT_WEIGHT"] = drBomProductMaterial["UNIT_WEIGHT"];
                            dr["TOTAL_WEIGHT"] = Convert.ToDecimal(drBomProductMaterial["UNIT_WEIGHT"].ToString()) * m.Qty;
                            dr["PICKING_TYPE"] = drBomProductMaterial["MANUFACTURING_TYPE"];
                            dr["PICKING_MODEL"] = drBomProductMaterial["PICKING_MODEL"];
                            dr["STATUS"] = "PIKI01";
                            dr["PLAN_QTY"] = m.Qty;
                            dr["ORDER_ITEM_CODE"] = m.OrderItemCode;
                            MstProductEntity mProduct = MstProductBs.GetMstProductTypeByID(m.ProductId);
                            dr["PRODUCT_NAME"] = mProduct.ProductName;
                            dr["STD_NAME"] = mProduct.StdName;
                            dr["MATERIAL"] = mProduct.Material;
                            dr["MATERIAL_PRODUCT_NAME"] = drBomProductMaterial["MATERIAL_NAME"];
                            MstProductEntity mProductMaterial = MstProductBs.GetMstProductTypeByID(drBomProductMaterial["MATERIAL_ID"].ToString());
                            dr["MATERIAL_STD_NAME"] = mProductMaterial.StdName;
                            dt.Rows.Add(dr);
                        }
                    }
                    else
                    {
                        DataRow dr = dt.NewRow();
                        dr["PICKING_MATERIAL_ITEM_ID"] = Guid.NewGuid().ToString();
                        dr["PLAN_ORDER_ITEM_ID"] = m.PlanOrderItemId;
                        dr["PRODUCT_TECHNIC_ID"] = dtExistedPickingStation.Rows[0]["PRODUCT_TECHNIC_ID"];
                        dr["QTY"] = m.Qty;
                        dr["STATUS"] = "PIKI01";
                        dr["PLAN_QTY"] = m.Qty;
                        dr["ORDER_ITEM_CODE"] = m.OrderItemCode;
                        MstProductEntity mProduct = MstProductBs.GetMstProductTypeByID(m.ProductId);
                        dr["PRODUCT_NAME"] = mProduct.ProductName;
                        dr["STD_NAME"] = mProduct.StdName;
                        dr["MATERIAL"] = mProduct.Material;
                        dt.Rows.Add(dr);
                    }
                }
            }
            #endregion
            #region 修改&&查看
            else if (ThisActionType == ActionType.Modify || ThisActionType == ActionType.View)
            {
                if (mSelectedPickingMaterial == null)
                    return;
                string Condition = " AND PPMI.PICKING_MATERIAL_ID='" + mSelectedPickingMaterial.PickingMaterialId + "' ";
                DataTable dt = ProdPickingMaterialItemBs.GetDtPickingMaterialItemByCondition(Condition, "");
                if (dt == null)
                    return;
                foreach (DataRow dr in dt.Rows)
                {
                    DataTable dtPickedQty = ProdPickingMaterialItemBs.GetDtTotalPickedQtyByItemID(dr["PLAN_ORDER_ITEM_ID"].ToString(), PickingOrderItemType.PCKIT01.ToString());
                    if (dtPickedQty != null && dtPickedQty.Rows.Count > 0)
                        dr["PICKED_QTY"] = dtPickedQty.Rows[0]["TOTAL_QTY"];
                    else dr["PICKED_QTY"] = 0;
                }
                dt.AcceptChanges();
                gvMain.DataSource = dt;
            }
            #endregion
        }

        private bool CheckData()
        {
            if (string.IsNullOrEmpty(cmbPickingType.Text) || cmbPickingType.SelectedValue == null)
            {
                cmbPickingType.Focus();
                MessageBox.Show("下料类型不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (string.IsNullOrEmpty(txtPickingDpt.Text))
            {
                txtPickingDpt.Focus();
                MessageBox.Show("下料部门不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (string.IsNullOrEmpty(txtPickingPerson.Text))
            {
                txtPickingPerson.Focus();
                MessageBox.Show("下料人不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (dtpPlanDeliveryDate.EditValue == null)
            {
                dtpPlanDeliveryDate.Focus();
                MessageBox.Show("计划交期不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            //检查GRID数据
            DataTable dt = gvMain.DataSource as DataTable;
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("放料清单不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            foreach (DataRow dr in dt.Rows)
            {
                if (string.IsNullOrEmpty(dr["ORDER_ITEM_CODE"].ToString()))
                {
                    MessageBox.Show("工令单不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(dr["MATERIAL_PRODUCT_NAME"].ToString()))
                {
                    MessageBox.Show("材料名称不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(dr["QTY"].ToString()))
                {
                    MessageBox.Show("放料数量不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(dr["PLAN_DELIVERY_DATE"].ToString()))
                {
                    MessageBox.Show("计划完成期不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(dr["PICKING_TYPE"].ToString()))
                {
                    MessageBox.Show("放料类型不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(dr["PICKING_MODEL"].ToString()))
                {
                    MessageBox.Show("放料规格不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(dr["UNIT_WEIGHT"].ToString()))
                {
                    MessageBox.Show("标准单重不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(dr["TOTAL_WEIGHT"].ToString()))
                {
                    MessageBox.Show("标准总重不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
            }
            return true;
        }

        private void SetEntity()
        {
            if (ThisActionType == ActionType.New)
            {
                mSelectedPickingMaterial = new ProdPickingMaterialEntity();
                mSelectedPickingMaterial.PickingMaterialId = Guid.NewGuid().ToString();
                mSelectedPickingMaterial.PickingType = cmbPickingType.SelectedValue.ToString();
                mSelectedPickingMaterial.PickingDepartment = ((MstDepartmentEntity)txtPickingDpt.Tag).DepartmentId;
                mSelectedPickingMaterial.PickingPerson = ((MstPersonEntity)txtPickingPerson.Tag).PersonId;
                mSelectedPickingMaterial.Remark = txtRemark.Text;
                mSelectedPickingMaterial.CreatedBy = Common.CommonParameter.CurrentUser.PersonId;
                mSelectedPickingMaterial.CreatedDate = DateTime.Now;
                mSelectedPickingMaterial.LastModifiedBy = Common.CommonParameter.CurrentUser.PersonId;
                mSelectedPickingMaterial.LastModifiedDate = DateTime.Now;
                mSelectedPickingMaterial.Status = "PIK01";
                mSelectedPickingMaterial.PlanDeliveryDate = Convert.ToDateTime(dtpPlanDeliveryDate.EditValue.ToString());

            }
            else if (ThisActionType == ActionType.Modify)
            {
                if (mSelectedPickingMaterial == null)
                {
                    MessageBox.Show("放料单不存在，请联系管理员！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                mSelectedPickingMaterial.PickingType = cmbPickingType.SelectedValue.ToString();
                mSelectedPickingMaterial.PickingDepartment = ((MstDepartmentEntity)txtPickingDpt.Tag).DepartmentId;
                mSelectedPickingMaterial.PickingPerson = ((MstPersonEntity)txtPickingPerson.Tag).PersonId;
                mSelectedPickingMaterial.Remark = txtRemark.Text;
                mSelectedPickingMaterial.LastModifiedBy = Common.CommonParameter.CurrentUser.PersonId;
                mSelectedPickingMaterial.LastModifiedDate = DateTime.Now;
                mSelectedPickingMaterial.PlanDeliveryDate = Convert.ToDateTime(dtpPlanDeliveryDate.EditValue.ToString());
            }
        }

        private bool SavePickingOrder()
        {
            DataTable dt = (DataTable)gvMain.DataSource;
            if (ThisActionType == ActionType.New)
            {
                if (!ProdPickingMaterialBs.SaveManufacturePickingOrder(true, mSelectedPickingMaterial, dt, listDel))
                {
                    MessageBox.Show("保存失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
            }
            else if (ThisActionType == ActionType.Modify)
            {
                if (!ProdPickingMaterialBs.SavePickingOrder(false, mSelectedPickingMaterial, dt, listDel))
                {
                    MessageBox.Show("保存失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
            }
            return true;
        }
        #endregion

        #region events
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            Init();
            BindComboBox();
            SetField();
            BindGrid();
        }

        private void txtPickingDpt_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {

        }

        private void txtPickingPerson_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {

        }

        private void dtpPlanDeliveryDate_EditValueChanged(object sender, EventArgs e)
        {
            if (dtpPlanDeliveryDate.EditValue == null)
                return;
            DataTable dt = (DataTable)gvMain.DataSource;
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    dr["PLAN_DELIVERY_DATE"] = (DateTime)dtpPlanDeliveryDate.EditValue;
                }
            }
        }

        private void tsNew_Click(object sender, EventArgs e)
        {
            DataTable dt = gvMain.DataSource as DataTable;
            DataRow dr = dt.NewRow();
            dt.Rows.Add(dr);
        }
        private List<ProdPickingMaterialItemEntity> listDel = new List<ProdPickingMaterialItemEntity>();
        private void tsDel_Click(object sender, EventArgs e)
        {
            if (gridView1.FocusedRowHandle < 0)
                return;
            DataRow dr = gridView1.GetDataRow(gridView1.FocusedRowHandle);
            DataTable dt = gvMain.DataSource as DataTable;
            if (ThisActionType == ActionType.Modify)
            {
                ProdPickingMaterialItemEntity m = new ProdPickingMaterialItemEntity(dr);
                listDel.Add(m);
            }
            dt.Rows.Remove(dr);
        }

        private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            frmMaintainWorkingOrderQuery frm = new frmMaintainWorkingOrderQuery();
            if (frm.ShowDialog() == DialogResult.OK && frm.SelectedProdPlanOrderItem != null)
            {      
                //检查所选择的工令单是否已存在
                DataTable dt = gvMain.DataSource as DataTable;
                DataRow[] arryDataRow = dt.Select("PLAN_ORDER_ITEM_ID='" + frm.SelectedProdPlanOrderItem.PlanOrderItemId + "'");
                if (arryDataRow != null && arryDataRow.Length > 0)
                {
                  
                    MessageBox.Show("所选择的工令单已在当前放料计划中！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                //所选择工令单是否存在放料工序
                DataTable dtExistedPickingStation = ProdProductTechnicBs.GetExistedPickingStationByPlanOrderItemID(frm.SelectedProdPlanOrderItem.PlanOrderItemId);
                if (dtExistedPickingStation.Rows.Count == 0)
                {
                    MessageBox.Show("所选择的工令单不存在放料工序，无法放料！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                //将所选工令单数据存入GRID
                //DataRow dr = dt.NewRow();
                int nFocusedRowHandle = gridView1.FocusedRowHandle;
                DataRow dr = gridView1.GetDataRow(nFocusedRowHandle); 
                dr["ORDER_ITEM_CODE"] = frm.SelectedProdPlanOrderItem.PlanOrderItemId;//*
                //查询工令单是否存在BOM MATERIAL清单
                DataTable dtBomMaterial = ProjMBOMMaterialBs.GetDtAllByProductID(frm.SelectedProdPlanOrderItem.ProductId);
                if (dtBomMaterial.Rows.Count > 0)
                {
                    foreach (DataRow drBomProductMaterial in dtBomMaterial.Rows)
                    {
                        dr["PICKING_MATERIAL_ITEM_ID"] = Guid.NewGuid().ToString();
                        dr["PLAN_ORDER_ITEM_ID"] = frm.SelectedProdPlanOrderItem.PlanOrderItemId;
                        dr["PRODUCT_TECHNIC_ID"] = dtExistedPickingStation.Rows[0]["PRODUCT_TECHNIC_ID"];
                        dr["QTY"] = frm.SelectedProdPlanOrderItem.Qty;
                        dr["STATUS"] = "PIKI01";
                        dr["PLAN_QTY"] = frm.SelectedProdPlanOrderItem.Qty;
                        dr["ORDER_ITEM_CODE"] = frm.SelectedProdPlanOrderItem.OrderItemCode;
                        MstProductEntity mProduct = MstProductBs.GetMstProductTypeByID(frm.SelectedProdPlanOrderItem.ProductId);
                        dr["PRODUCT_NAME"] = mProduct.ProductName;
                        dr["STD_NAME"] = mProduct.StdName;
                        dr["MATERIAL"] = mProduct.Material;

                        dr["MATERIAL_ID"] = drBomProductMaterial["MATERIAL_ID"];
                        dr["NET_SIZE"] = drBomProductMaterial["NET_SIZE"];
                        dr["GROSS_SIZE"] = drBomProductMaterial["GROSS_SIZE"];
                        dr["UNIT_WEIGHT"] = drBomProductMaterial["UNIT_WEIGHT"];
                        dr["TOTAL_WEIGHT"] = Convert.ToDecimal(drBomProductMaterial["UNIT_WEIGHT"].ToString()) * frm.SelectedProdPlanOrderItem.Qty;
                        dr["PICKING_TYPE"] = drBomProductMaterial["MANUFACTURING_TYPE"];
                        dr["PICKING_MODEL"] = drBomProductMaterial["PICKING_MODEL"];
                        //dt.Rows.Add(dr);//*
                    }
                }
                else
                {
                    dr["PICKING_MATERIAL_ITEM_ID"] = Guid.NewGuid().ToString();
                    dr["PLAN_ORDER_ITEM_ID"] = frm.SelectedProdPlanOrderItem.PlanOrderItemId;
                    dr["PRODUCT_TECHNIC_ID"] = dtExistedPickingStation.Rows[0]["PRODUCT_TECHNIC_ID"];
                    dr["QTY"] = frm.SelectedProdPlanOrderItem.Qty;
                    dr["STATUS"] = "PIKI01";
                    dr["PLAN_QTY"] = frm.SelectedProdPlanOrderItem.Qty;
                    dr["ORDER_ITEM_CODE"] = frm.SelectedProdPlanOrderItem.OrderItemCode;
                    MstProductEntity mProduct = MstProductBs.GetMstProductTypeByID(frm.SelectedProdPlanOrderItem.ProductId);
                    dr["PRODUCT_NAME"] = mProduct.ProductName;
                    dr["STD_NAME"] = mProduct.StdName;
                    dr["MATERIAL"] = mProduct.Material;
                    //dt.Rows.Add(dr);//*
                }
            }
        }

        private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            frmMaintainProductQuery frm = new frmMaintainProductQuery();
            //frm.sCondition = " and C.PRODUCT_TYPE_CODE='d' ";
            if (frm.ShowDialog() == DialogResult.OK && frm.SelectedProduct != null)
            {
                int nFocusedRowHandle = gridView1.FocusedRowHandle;
                DataRow drFocusedRow = gridView1.GetDataRow(nFocusedRowHandle);
                drFocusedRow["MATERIAL_ID"] = frm.SelectedProduct.ProductId;
                drFocusedRow["STATUS"] = "PIKI01";
                drFocusedRow["MATERIAL_PRODUCT_NAME"] = frm.SelectedProduct.ProductName;
                drFocusedRow["MATERIAL_STD_NAME"] = frm.SelectedProduct.StdName;

            }
        }

        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName.Equals("QTY"))
            {
                DataRow dr = gridView1.GetDataRow(e.RowHandle);
                if (string.IsNullOrEmpty(dr["UNIT_WEIGHT"].ToString()) == false)
                {
                    dr["TOTAL_WEIGHT"] = Convert.ToDecimal(e.Value) * Convert.ToDecimal(dr["UNIT_WEIGHT"].ToString());
                }
            }
            else if (e.Column.FieldName.Equals("UNIT_WEIGHT"))
            {
                DataRow dr = gridView1.GetDataRow(e.RowHandle);
                if (string.IsNullOrEmpty(dr["QTY"].ToString()) == false)
                {
                    dr["TOTAL_WEIGHT"] = Convert.ToDecimal(e.Value) * Convert.ToDecimal(dr["QTY"].ToString());
                }
            }
        }

        protected override void Click_Save()
        {
            if (CheckData() == false)
            {
                return;
            }
            SetEntity();
            if (SavePickingOrder())
            {
                MessageBox.Show("保存成功！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
            }
            mSelectedPickingMaterial = null;
            return;
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            //if (mSelectedPickingMaterial == null)
            //{
            //    MessageBox.Show("放料单尚未保存，无法打印！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
            //frmPrintFormPickingOrder frm = new frmPrintFormPickingOrder(mSelectedPickingMaterial, (DataTable)gvMain.DataSource);
            //frm.MdiParent = this.MdiParent;
            //frm.ShowDialog();
        }
        #endregion

    }
}
